<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:o="http://www.kadm-Software.ua/OOPLang"
    xmlns:op="http://www.kadm-Software.ua/OperationsLang"
    xmlns:l="http://www.kadm-Software.ua/LiteralsLang"
    xmlns:f="http://www.kadm-Software.ua/FunctionsLang"
    xmlns="http://www.kadm-Software.ua/AlgorytmicLang">

    <xsl:output method="xml" version="1.0" encoding="Windows-1251"/>

    <!--<xsl:template match="xsl:stylesheet">
        <o:calss name="xsl_stylesheet_{position()}" extends="xsl">-->
            <!--<xsl:apply-templates select="xsl:template[@match]" />
            <xsl:for-each select="xsl:template">
                <xsl:variable name="mode">
                    <xsl:choose>
                        <xsl:when test="@mode">'<xsl:value-of select="@mode" />'</xsl:when>
                        <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
            <xsl:if test="@name">
            $this->procedures['<xsl:value-of select="@name" />'] = <xsl:value-of select="position()" />;</xsl:if>
            $this->templates[<xsl:value-of select="$mode" />][<xsl:value-of select="position()" />] = array ( 'match' => '<xsl:value-of select="@match" />', 'priority' => xsl::getPatternPriority('<xsl:value-of select="@match" />'));</xsl:for-each>

            foreach ( $templates as $num => $template ) {
                $node_set = $this->query($template["match"]);
                for ($i = 0; $i &lt; $node_set->length; $i++) {
                    if ($templates[$node_set->item($i)->template]["priority"] &lt; $template["priority"]) {
                        $node_set->item($i)->template = $num;
                    }
                }
            }-->
            <!--<xsl:apply-templates />
        </o:class>
    </xsl:template>-->

    <!--<xsl:template match="xsl:apply-templates">
        <xsl:variable name="select">
            <xsl:choose>
                <xsl:when test="@select"><xsl:value-of select="@select" /></xsl:when>
                <xsl:otherwise>text()|*</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        $params = array (
        <xsl:apply-templates select="xsl:with-param"/>
        );

        $contextNode =&amp; $this->getCurrNode();
        $this->toDeepen();
        $this->setCurrNodeSet($this->query(html_entity_decode('<xsl:value-of select="$select" />', ENT_QUOTES)), $contextNode);
        <xsl:apply-templates select="xsl:sort" />
        for ($i = 0; $i &lt; $this->getCurrNodeSet->length; $i++) {
            $this->setCurrNode($i+1);
            $template = 'template_'.$this->getCurrNode()->template;
            $this->$$template($params);
        }
        $this->toRise();
    </xsl:template>

    <xsl:template match="xsl:with-param">
        "<xsl:value-of select="@name" />" = $this->query(html_entity_decode('<xsl:value-of select="@select" />', ENT_QUOTES)), $this->getCurrNode())<xsl:if test="position() &lt; last()">,</xsl:if>
    </xsl:template>

    <xsl:template match="xsl:sort">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="xsl:for-each">
        xsl::setCurrNodeSet($this->query($template["match"], ));
        <xsl:apply-templates select="xsl:sort" />
        $nodeSet = xpath($currNode, "<xsl:value-of select="@select" />");
        for ($i = 0; $i &lt; $nodeSet.length; $i++) {
            <xsl:apply-templates />
        }
    </xsl:template>-->


    <!--<xsl:template match="xsl:template/xsl:param">
        $node = $this->resultCurrNode->createChild("<xsl:value-of select="name()" />");
        $this->resultCurrNode =&amp; $node;
        <xsl:apply-templates select="@*"/>
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="xsl:template//*/@*">
        $this->resultCurrNode->createAttribute("<xsl:value-of select="name()" />", "<xsl:value-of select="." />");
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="xsl:*" />
    <xsl:template match="xsl:template//xsl:*" />

    <xsl:template match="xsl:template/xp:match">
        <xsl:apply-templates />
    </xsl:template>-->

    <xsl:template match="xsl:template">
        <op:assign>
            <ident>_x_tpl_<xsl:value-of select="count(preceding-sibling::xsl:template)+1" /></ident>
            <l:function>
                <l:args />
                <l:code>
                    <xsl:apply-templates />
                </l:code>
            </l:function>
        </op:assign>
    </xsl:template>

    <xsl:template match="xsl:for-each">
        <op:assign>
            <o:property>
                <o:this />
                <ident>current_node_set</ident>
            </o:property>
            <f:call>
                <f:function>
                    <o:property>
                        <o:this />
                        <ident>xpath</ident>
                    </o:property>
                </f:function>
                <f:args>
                    <f:call>
                        <f:function>
                            <o:property>
                                <o:this />
                                <ident>entity_decode</ident>
                            </o:property>
                        </f:function>
                        <f:args>
                            <l:string><xsl:value-of select="@test" /></l:string>
                        </f:args>
                    </f:call>
                </f:args>
            </f:call>
        </op:assign>
        <for>
            <init>
                <op:assign>
                    <o:property>
                        <o:this />
                        <ident>position</ident>
                    </o:property>
                    <l:int>1</l:int>
                </op:assign>
            </init>
            <cond>
                <op:le>
                    <o:property>
                        <o:this />
                        <ident>position</ident>
                    </o:property>
                    <o:property>
                        <o:property>
                            <o:this />
                            <ident>current_node_set</ident>
                        </o:property>
                        <ident>length</ident>
                    </o:property>
                </op:le>
            </cond>
            <after-iter>
                <op:suf-inc>
                    <o:property>
                        <o:this />
                        <ident>position</ident>
                    </o:property>
                </op:suf-inc>
            </after-iter>
            <cmd>
                <block>
                    <xsl:apply-templates select="node()[name()!='xsl:sort']" />
                </block>
            </cmd>
        </for>
    </xsl:template>

<!-- Process with conditions -->
<!-- BEGIN -->
    <xsl:template match="xsl:if">
        <if>
            <value>
                <f:call>
                    <f:function>
                        <o:property>
                            <o:this />
                            <ident>xpath</ident>
                        </o:property>
                    </f:function>
                    <f:args>
                        <f:call>
                            <f:function>
                                <o:property>
                                    <o:this />
                                    <ident>entity_decode</ident>
                                </o:property>
                            </f:function>
                            <f:args>
                                <l:string><xsl:value-of select="@test" /></l:string>
                            </f:args>
                        </f:call>
                    </f:args>
                </f:call>
            </value>
            <cmd>
                <xsl:apply-templates />
            </cmd>
        </if>
    </xsl:template>

    <xsl:template match="xsl:choose">
        <switch>
            <value>
                <l:bool>true</l:bool>
            </value>
            <cmd>
                <xsl:apply-templates />
            </cmd>
        </switch>
    </xsl:template>

    <xsl:template match="xsl:when">
        <case>
            <value>
                <f:call>
                    <f:function>
                        <o:property>
                            <o:this />
                            <ident>xpath</ident>
                        </o:property>
                    </f:function>
                    <f:args>
                        <f:call>
                            <f:function>
                                <o:property>
                                    <o:this />
                                    <ident>entity_decode</ident>
                                </o:property>
                            </f:function>
                            <f:args>
                                <l:string><xsl:value-of select="@test" /></l:string>
                            </f:args>
                        </f:call>
                    </f:args>
                </f:call>
            </value>
            <cmd>
                <xsl:apply-templates />
                <break />
            </cmd>
        </case>
    </xsl:template>

    <xsl:template match="xsl:otherwise">
        <default>
            <xsl:apply-templates />
        </default>
    </xsl:template>

    <xsl:template match="xsl:element">
        <f:call>
            <f:function>
                <o:property>
                    <o:this />
                    <ident>appendElement</ident>
                </o:property>
            </f:function>
            <f:args>
                <f:call>
                    <f:function>
                        <o:property>
                            <o:this />
                            <ident>createValue</ident>
                        </o:property>
                    </f:function>
                    <f:args>
                        <f:call>
                            <f:function>
                                <o:property>
                                    <o:this />
                                    <ident>entity_decode</ident>
                                </o:property>
                            </f:function>
                            <f:args>
                                <l:string><xsl:value-of select="@name" /></l:string>
                            </f:args>
                        </f:call>
                    </f:args>
                </f:call>
            </f:args>
        </f:call>
    </xsl:template>

    <xsl:template match="xsl:text">
        <f:call>
            <f:function>
                <o:property>
                    <o:this />
                    <ident>appendText</ident>
                </o:property>
            </f:function>
            <f:args>
                <f:call>
                    <f:function>
                        <o:property>
                            <o:this />
                            <ident>createValue</ident>
                        </o:property>
                    </f:function>
                    <f:args>
                        <f:call>
                            <f:function>
                                <o:property>
                                    <o:this />
                                    <ident>entity_decode</ident>
                                </o:property>
                            </f:function>
                            <f:args>
                                <l:string><xsl:value-of select="." /></l:string>
                            </f:args>
                        </f:call>
                    </f:args>
                </f:call>
            </f:args>
        </f:call>
    </xsl:template>
<!--    <xsl:template match="xsl:choose">
        <l>switch (true) {</l>
        <l />
        <xsl:apply-templates />
        <l>}</l>
    </xsl:template>

    <xsl:template match="xsl:when">
        <l>case $this->xpath(xsl::entity_decode("<xsl:value-of select="@test" />")):</l>
            <block>
            <xsl:apply-templates />
            <l>break;</l>
            </block>
        <l />
    </xsl:template>

    <xsl:template match="xsl:otherwise">
        <l>default:</l>
            <block><xsl:apply-templates /></block>
        <l />
    </xsl:template>
--><!-- END -->

</xsl:stylesheet>